package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysGenTest;
import com.ruoyi.system.service.ISysGenTestService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * testController
 * 
 * @author liupan
 * @date 2021-05-21
 */
@Controller
@RequestMapping("/system/genTest")
public class SysGenTestController extends BaseController
{
    private String prefix = "system/genTest";

    @Autowired
    private ISysGenTestService sysGenTestService;

    @RequiresPermissions("system:genTest:view")
    @GetMapping()
    public String genTest()
    {
        return prefix + "/genTest";
    }

    /**
     * 查询test列表
     */
    @RequiresPermissions("system:genTest:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysGenTest sysGenTest)
    {
        startPage();
        List<SysGenTest> list = sysGenTestService.selectSysGenTestList(sysGenTest);
        return getDataTable(list);
    }

    /**
     * 导出test列表
     */
    @RequiresPermissions("system:genTest:export")
    @Log(title = "test", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysGenTest sysGenTest)
    {
        List<SysGenTest> list = sysGenTestService.selectSysGenTestList(sysGenTest);
        ExcelUtil<SysGenTest> util = new ExcelUtil<SysGenTest>(SysGenTest.class);
        return util.exportExcel(list, "test数据");
    }

    /**
     * 新增test
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存test
     */
    @RequiresPermissions("system:genTest:add")
    @Log(title = "test", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysGenTest sysGenTest)
    {
        return toAjax(sysGenTestService.insertSysGenTest(sysGenTest));
    }

    /**
     * 修改test
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysGenTest sysGenTest = null;
        if(id == null || id ==  -1){
            sysGenTest = new SysGenTest();
        }else{
            sysGenTest = sysGenTestService.selectSysGenTestById(id);
        }
        mmap.put("sysGenTest", sysGenTest);
        return prefix + "/edit";
    }

    /**
     * 修改保存test
     */
    @RequiresPermissions("system:genTest:edit")
    @Log(title = "test", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysGenTest sysGenTest)
    {
        return toAjax(sysGenTestService.updateSysGenTest(sysGenTest));
    }

    /**
     * 删除test
     */
    @RequiresPermissions("system:genTest:remove")
    @Log(title = "test", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysGenTestService.deleteSysGenTestByIds(ids));
    }
}
